import { defineStore } from "pinia";
import { handlerAccept, initOssApi } from "@/components/globalUtils/UploadFile";

export const ossStore = defineStore('oss', {
    state: () => {
        return {
            initOss: null,// 不能开启持久化缓存 存入localStorage取出时上传方法丢失
            inUploadCount: 0,// 为上传完成的数量
            excelAccept: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel', // 只能选择 excel
            excelTypeRule: 'xls, xlsx, csv',
            imageTypeRule: 'jpg, jpeg, png, gif',
            videoTypeRule: 'mov, avi, mp4',
        }
    },
    getters: {
        // 上传完成
        updatedFinish() {
            return this.inUploadCount <= 0;
        },
        // 只能选择 图片
        imageAccept() {
            return handlerAccept(this.imageTypeRule, 'image');
        },
        // 只能选择 视频
        videoAccept() {
            return handlerAccept(this.videoTypeRule, 'video');
        },
    },
    actions: {
        async getInitOss() {
            this.initOss = await initOssApi();
            return this.initOss
        },
        addInUploadCount() {
            this.inUploadCount++;
        },
        remInUploadCount() {
            this.inUploadCount--;
        },
    },
});